package com.balusoft.shared.domain;

import java.io.Serializable;


/**
 */
public class Name implements Serializable
{
	private static final long serialVersionUID = 1L;
	
	public String firstName;
	public String lastName;
	public String middleName;
	
	public String getFirstName() {
		return firstName;
	}

	public void setFirstName(String firstName) {
		this.firstName = firstName;
	}

	public String getLastName() {
		return lastName;
	}

	public void setLastName(String lastName) {
		this.lastName = lastName;
	}

	public String getMiddleName() {
		return middleName;
	}

	public void setMiddleName(String middleName) {
		this.middleName = middleName;
	}

	public Name() {
	}

	public Name(String firstName, String lastName, String middleName)
	{
		this.firstName = firstName;
		this.lastName = lastName;
		this.middleName = middleName; 
	}
	
	public boolean equals(Object o)
	{
		// Doesn't do null check on names but good enough
		return o != null
			&& o.getClass() == this.getClass()
			&& safeEquals(((Name)o).firstName, this.firstName)
			&& safeEquals(((Name)o).lastName, this.lastName)
		    && safeEquals(((Name)o).middleName, this.middleName);
	}
	
	@Override
	public int hashCode()
	{
		return firstName.hashCode();
	}

	/**
	 * Null safe equality comparison
	 */
	boolean safeEquals(Object o1, Object o2)
	{
		return (o1 == o2) || ((o1 != null) && o1.equals(o2));
	}

	@Override
	public String toString() {		
		return "Frist:" + this.firstName 
				+ " last:" + this.lastName 
				+ " middle:" + this.middleName;
	}
	
	public String getTitle(){
		return this.lastName + " " + this.firstName + " " + this.middleName;
	}
}
